<template>
	<!-- 顶部背景 -->
	<view class="normal-login-container" ref="poster" @touchmove.stop.prevent>
		<view class="top-bg" :style="{backgroundImage:`url(${baseUrl}/upload/qiniu/images/icon/work_bg.png)`}">

		</view>
		<view class="top">
			<view class="logo-box">
				<view style="height: var(--status-bar-height); width: 100%;"></view>
				<u-navbar :isBack='false' title="我的" :titleStyle="{fontSize:'18',fontWeight: 'bold',color:'#fff'}"
					bgColor="transparent" :autoBack="false">
				</u-navbar>
				<!-- 顶部下拉 -->
			</view>
		</view>

		<view class="user-box">
			<view class="box-title">
				<span class="box-line"></span>信息核销
			</view>
			<view class="cell-box">
				<u-cell title="所属店铺" :value="autoname">
					<text slot="icon" class="cart cart-suoshucangku" style="font-size: 36rpx;color: #6E6E6E;"></text>
				</u-cell>
				<!-- <u-cell icon="share" title="关于我们" :isLink="true"
					:customStyle="{paddingTop:'15rpx',paddingBottom:'10rpx'}" @click="handleAbout">
					<text slot="icon" class="cart cart-jurassic_pc" style="font-size: 36rpx;color: #6E6E6E;"></text>
				</u-cell> -->
				<u-cell icon="share" title="客服" :border="false" :isLink="true" @click="handleCustomer">
					<text slot="icon" class="cart cart-kefu" style="font-size: 36rpx;color: #6E6E6E;"></text>
				</u-cell>
				<u-cell icon="scan" title="扫一扫" :border="false" :isLink="true" @click="scanCode">
					<u-icon slot="scan" name="file-text" class="cart cart-kefu" size="16"></u-icon>
				</u-cell>
				<u-cell icon="share" title="活动总结" :border="false" :isLink="true" @click="handleActiveSummary"
					v-if="identity === 1">
					<u-icon slot="share" name="file-text" class="cart cart-kefu" size="16"></u-icon>
				</u-cell>
				<u-cell icon="weixin-fill" title="微信绑定" :border="false" :isLink="true" @click="goEdit">
					<u-icon slot="weixin-fill" name="file-text" class="cart cart-kefu" size="16"></u-icon>
				</u-cell>
				<!-- <u-cell icon="share" title="隐私协议" :border="false" :isLink="true"
					:customStyle="{paddingTop:'15rpx',paddingBottom:'10rpx'}" @click="handleAgreement">
					<u-icon slot="icon" name="file-text" class="cart cart-kefu" size="16"></u-icon>
				</u-cell> -->
				<!-- <u-cell icon="share" title="诚意金订单" :border="false" :isLink="true"
					:customStyle="{paddingTop:'15rpx',paddingBottom:'10rpx'}" @click="handleOrder">
					<u-icon slot="icon" name="file-text" class="cart cart-kefu" size="16"></u-icon>
				</u-cell> -->
				<u-cell icon="/static/images/out.png" title="退出" :border="false" :isLink="true"
					:customStyle="{paddingTop:'15rpx',paddingBottom:'10rpx'}" @click="logoutOk">
				</u-cell>
			</view>
		</view>
		<view class="user-box" style="margin-top: 40rpx;">
			<view class="order-box">
				<view class="box-title">
					<span class="box-line"></span>诚意金订单
				</view>
				<view class="nr-sort">
					<view class="item-sort" @click="staffShow=true">{{staffName}}<u-icon name="arrow-down"></u-icon>
					</view>
				</view>
			</view>
			<view class="cell-box">
				<scroll-view :scroll-top="scrollTop" scroll-y="true" :class="identity === 1 ? 'scroll-Y1': 'scroll-Y2'"
					@scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">

					<view class="nr-item">
						<view class="item" v-for="(item,index) in listData" :key="index">
							<view class="img-box">
								<view class="img">
									<u--image :showLoading="true" :src="item.thumb" width="180rpx"
										height="204rpx"></u--image>
									<view class="img-state" v-if="item.state ===1 && item.cash > 0">
										{{cashStatus[item.cash]}}
									</view>
									<view class="img-state"
										v-else-if="item.amount_check_status === 1 && item.state === 1 ">已核销</view>
									<view class="img-state" v-else>
										{{orderStatus[item.state]}}
									</view>
								</view>
							</view>
							<view class="info-box">
								<view class="info-title">
									{{item.title || ''}}
								</view>
								<view class="info-size">
									意向车型：{{item.cart}}
								</view>
								<view class="info-size">
									订单号：{{item.order_sn}}
								</view>
								<view class="info-size">
									<span>客户：{{item.real_name}}</span> <span class="info-price">{{item.amount}}元</span>
								</view>
								<view class="info-size">
									<view>
										销售顾问：{{item.staff_real_name || ''}} {{item.pay_time}}
									</view>

								</view>
								<view class="info-size info-but">
									<view v-if="identity === 2">
										<span class="but-tx" @click="getCashBefore(item.id, 0)">提现</span><span
											class="but-tk" @click="getCashBefore(item.id, 1)">退款</span>
									</view>
								</view>

							</view>
						</view>

						<!-- 为空 -->
						<view class=""
							style="width: 100%;height: 600rpx;display: flex;justify-content: center;align-items: center;"
							v-if="listData.length == 0">
							<u-empty mode="list">

							</u-empty>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<!-- 销售顾问弹出层 -->
		<u-picker :show="staffShow" @confirm="staffSelectOk" closeOnClickOverlay keyName="label" @close="staffclose"
			:columns="staffList" @cancel="staffSelectNot"></u-picker>
		<u-modal :show="model.show" showCancelButton :title="model.title" :content='model.content' @confirm="emconfirm"
			@cancel="emcancel">
			<u-toast ref="uToast2"></u-toast>
		</u-modal>
		<my-tabbar :currentTab='4' />
	</view>
</template>

<script>
	import {
		getCodeImg
	} from '@/api/login'
	import {
		removeToken

	} from '@/utils/auth'
	import {
		getUserProfile,
		logout
	} from "@/api/system/user"
	import {
		getLabel,
		verificationAmount
	} from '@/api/system/index'
	import {
		getOrderList,
		getOrderCash
	} from '@/api/system/order'
	import {
		mapMutations,
		mapGetters
	} from "vuex";
	import {
		toast,
		showConfirm,
		tansParams,
		showokConfirm
	} from '@/utils/common'
	import config from '@/config'
	export default {
		data() {
			return {
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				navbar: 0, //状态栏高度
				statusBar: 0, // 状态栏高度 + 导航栏高度  
				customBar: 0, // 自定义标题与胶囊对齐高度
				codeUrl: "",
				captchaEnabled: true,
				baseUrl: config.baseUrl,
				staffShow: false, //销售顾问弹出状态
				staffList: [], //销售顾问列表
				queryParam: {
					page: 1,
					limit: 8,
					type: 0,
					activeId: null,
					staffId: null,
					summary: null
				},
				staffName: "销售顾问",
				listData: [], //订单数据
				orderStatus: {
					"-2": "退款审核拒绝",
					"-1": "退款中",
					"0": "未支付",
					"1": "已支付",
					"2": "已退款"
				},
				cashStatus: {
					"1": "提现中",
					"2": "已提现"
				},
				model: {
					show: false,
					title: '',
					content: '999898979',
					is_men: true,
					id: null,
					type: null
				},


			}
		},
		computed: {
			...mapGetters(["avatar", "nickname", "mobile", "position", 'autoname', 'identity'])
		},
		mounted() {

		},
		onLoad() {

		},
		created() {
			this.getUser()
		},
		onShow() {
			var stort_ac_id = uni.getStorageSync('active_id')
			var stort_ac_title = uni.getStorageSync('active_title')
			var stort_ac_key = uni.getStorageSync('summary');
			this.queryParam.activeId = stort_ac_id
			this.queryParam.summary = stort_ac_key
			this.typeName = stort_ac_title
			this.listData = []
			this.getWorkListData()
			this.getLabelList()
		},
		methods: {
			//获取用户信息
			getUser() {
				this.$store.dispatch('GetInfo').then(res => {})
			},
			async getLabelList() {
				var params = {
					activeId: this.queryParam.activeId
				}
				//获取销售顾问
				await getLabel(params).then(res => {
					if (!res.code) {
						var staffList = res.data.staffList
						var cartList = res.data.cartList
						if (staffList) {
							var arr = Object.entries(staffList).map(([key, value]) => {
								return {
									id: key,
									label: value
								};
							});
							var allObj = {
								id: null,
								label: "全部"
							}
							arr.unshift(allObj)
							this.staffList = [arr];
						}
						if (cartList) {
							var arr = Object.entries(cartList).map(([key, value]) => {
								return {
									id: key,
									label: value
								};
							});
							var allObj = {
								id: null,
								label: "全部"
							}
							arr.unshift(allObj)
							this.cartList = [arr];
						}
					}

				});
			},
			async getWorkListData() {
				getOrderList(this.queryParam).then(res => {
					if (!res.code) {
						this.listData = [...this.listData, ...res.data]
						this.total = res.count
					}
					this.listshow = false
				})
			},
			//提现或退款
			getCashBefore(id, type) {
				this.model = {
					show: true,
					title: type == 1 ? "确定要退款？" : "确定要提现？",
					content: '',
					is_men: false,
					id: id,
					type: type
				}
			},
			emcancel() {
				this.model = {
					show: false,
					title: '',
					content: '',
					is_men: true,
					id: null,
					type: null
				}

			},
			//确认提现
			emconfirm() {
				var _this = this
				var param = {
					type: _this.model.type,
					orderId: _this.model.id
				}
				getOrderCash(param).then(res => {
					if (res.code === 0) {
						_this.$refs.uToast2.show({
							type: 'success',
							message: '提交成功',
							complete() {
								_this.emcancel()
								_this.listData = []
								_this.getWorkListData()
							}

						})
					}

				})

			},
			//去修改
			goEdit() {
				this.$tab.navigateTo('/pagesA/mine/info/index')
			},
			logoutOk() {
				var that = this

				showConfirm('确认退出？').then(res => {
					if (res.confirm) {
						logout().then(res => {
							that.$refs.uToast.show({
								type: 'success',
								message: '退出成功',
								complete() {
									removeToken()
									uni.reLaunch({
										url: '/pages/login'
									})
								}

							})

						})

					}
				})


			},
			async staffSelectOk(e) {
				var data = e.value[0]
				this.queryParam.staffId = data.id
				this.staffName = data.label
				this.queryParam.page = 1
				this.listData = []
				this.staffShow = false
				await this.getWorkListData()
			},
			staffclose() {
				this.staffShow = false
			},
			staffSelectNot() {
				this.staffShow = false
			},
			async lower() {
				//判断当前数据数量是否
				if (this.listData.length >= this.total) return false

				this.queryParam.page++
				await this.getWorkListData()
			},
			upper: function(e) {

				// console.log(e)
			},
			scroll: function(e) {
				// console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop: function(e) {
				// 解决view层不同步的问题
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = 0
				});
				uni.showToast({
					icon: "none",
					title: "纵向滚动 scrollTop 值已被修改为 0"
				})
			},
			scanCode() {
				var _this = this
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						var errMsg = res.errMsg
						if (errMsg == "scanCode:ok") {
							var data = JSON.parse(res.result)
							var param = {
								activeId: data.activeId,
								orderId: data.orderId,
								userId: data.userId
							}
							_this.$refs.uToast.show({
								type: "loading",
								title: "正在核验",
								message: "正在核验",
								complete() {
									verificationAmount(param).then(res2 => {
										if (res2.code === 0) {
											uni.$u.toast('核销成功')
										}
									})
								},
							});
						} else {
							uni.$u.toast('扫码失败，请重试')
						}


						// verificationAmount
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
						// uni.$u.toast('核销成功')
					}
				});
			},
			handleAbout() {
				this.$tab.navigateTo('/pagesA/mine/about/index')
			},
			handleCustomer() {

				this.$tab.navigateTo('/pagesA/mine/customer/index')
			},
			handleAgreement() {

				this.$tab.navigateTo('/pagesA/mine/about/agreement')
			},
			handleOrder() {
				this.$tab.navigateTo('/pagesA/order/index')
			},
			handleActiveSummary() {
				this.$tab.navigateTo('/pagesA/index/activeSummary')
			},



		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F4F5FF;
	}

	.normal-login-container {
		width: 100%;

		.top-bg {
			position: absolute;
			width: 100%;
			height: 200rpx;
			background-size: cover;
			/* 背景图片覆盖整个元素 */
			background-position: center;
			/* 背景图片居中 */
			// background: linear-gradient(0deg, #FFFFFF 0%, #3477FC 100%);
			z-index: -100;
		}

		.scroll-Y1 {
			max-height: 550rpx
		}

		.scroll-Y2 {
			max-height: 650rpx
		}

		.top {
			position: relative;
			display: flex;
			flex-direction: column;
			z-index: 1000;

			.logo-box {

				width: 100%;
				height: 200rpx;
				// position: absolute;
				font-weight: bold;
				z-index: -100;
			}
		}

		.user-box {
			padding: 30rpx;
			margin: 0 auto;
			background-color: #fff;
			border-radius: 10rpx;

			.box-title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 35rpx;
				color: #303133;
				line-height: 36rpx;
				text-align: left;
				font-style: normal;
				text-transform: none;
			}

			.order-box {

				display: flex;
				justify-content: space-between;

				.nr-sort {

					display: flex;
					// justify-content: flex-start;
					// padding: 20rpx 25rpx;

					.item-sort {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: rgba(45, 52, 64, 0.85);

						text-align: left;
						font-style: normal;
						text-transform: none;
						margin-right: 40rpx;
						display: flex;
					}
				}

			}

			.box-line {
				width: 6rpx;
				height: 26rpx;
				padding: 0rpx 6rpx;
				background: #254EF8;
				border-radius: 436rpx 436rpx 436rpx 436rpx;
				margin-right: 20rpx;
			}

			.cell-box {
				display: block;
			}

		}

		.nr-item {
			width: 100%;
			border-radius: 5px;
			box-shadow: 0 0 1px #ccc;
			// padding: 20rpx 40rpx 20rpx 20rpx;
			margin-bottom: 20rpx;

			// margin-top: 40rpx;
			.item {
				width: 100%;
				display: flex;
				justify-content: flex-start;
				background-color: #FFFFFFFF;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				border-bottom: 1rpx solid #E5F1FF;

				.img-box {

					display: flex;
					justify-content: space-between;
					padding: 20rpx;
					justify-items: center;
					align-items: center;
					margin-right: 20rpx;

					.img {
						padding: 0rpx 10rpx;
						position: relative;
						width: 174rpx;
						height: 204rpx;

						.item-img {
							width: 174rpx;
							height: 204rpx;
						}

						.img-state {
							position: absolute;
							top: 0;
							background: #254EF8;
							border-radius: 10rpx 10rpx 10rpx 10rpx;
							padding: 10rpx;
							font-size: 16rpx;
							color: #fff;
						}
					}

				}

				.info-box {
					width: 100%;
					padding: 20rpx;

					.info-title {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: rgba(0, 0, 0, 0.85);
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}

					.info-size {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: rgba(0, 0, 0, 0.85);
						line-height: 40rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;

						.info-price {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 26rpx;
							color: rgba(230, 14, 14, 0.85);
							line-height: 48rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
							margin-left: 40rpx;
						}
					}

					.info-but {
						margin-top: 25rpx;
						display: flex;
						justify-content: flex-end;

						.but-tx {
							padding: 10rpx 40rpx;
							background: #254EF8;
							color: #fff;
							margin-right: 20rpx;
						}

						.but-tk {
							padding: 10rpx 30rpx;
							background: #FF911C;
							color: #fff;
							margin-right: 20rpx;
						}
					}

				}

				.title-box {
					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: rgba(0, 0, 0, 0.85);
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}

					.name-sf {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 16rpx;
						color: #254EF8;
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}
				}


			}

		}

	}
</style>